package com.spring.beans.factory.support;

import com.spring.BeanDefinition;
import com.spring.beans.BeansException;

import java.lang.reflect.InvocationTargetException;

/**
 * @Author: Asuka
 * @Description:
 * @create: 2025-04-14 15:43
 */


public class SimpleInstantiationStrategy implements InstantiationStrategy{



    //简单的bean实例化策略,根据无参构造实例
    @Override
    public Object instantiate(BeanDefinition beanDefinition) throws BeansException {
        Class beanClass = beanDefinition.getBeanClass();

        try {
            Object object = beanClass.getDeclaredConstructor().newInstance();
            return object;
        } catch (Exception e) {
            throw new BeansException("Failed to instantiate [" + beanClass.getName() + "]", e);
        }
    }
}
